package top.infopub.mgr.sys.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.infopub.generic.GenericController;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.model.sys.ParameterGroupDetail;
import top.infopub.model.sys.Parametergroup;
import top.infopub.tdp.sys.service.CodeGeneratorConfigService;
import top.infopub.tdp.sys.service.ParameterGroupDetailService;
import top.infopub.tdp.sys.service.ParametergroupService;

import com.github.pagehelper.Page;


/**
 * 数据字典参数管理
 * @author Awoke
 * @version 2018年10月15日
 * @see ParaMgrController
 * @since
 */
@Controller
@RequestMapping("/paraMgr")
public class ParaMgrController extends GenericController {

    @Autowired
    private ParametergroupService parametergroupService;

    @Autowired
    private ParameterGroupDetailService parameterGroupDetailService;

    @Autowired
    private CodeGeneratorConfigService codeGeneratorConfigService;

    /**编号类型*/
    private static final String PARAMGROUP_CODE = "sys_parameter_group";

    /**
     * 数据字典参数管理
     * @return
     */
    @RequestMapping("/paramGroup")
    public String paramGroup() {
        return "paraMgr/layparamgroup-list";
    }

    /**
     * 查询数据字典参数
     * @return
     */
    @RequestMapping("/queryParamGroup")
    public @ResponseBody RspVo<Parametergroup> queryParamGroup(Parametergroup parametergroup,
                                                                    ParamPage paramPage) {
        Page<Parametergroup> page = new Page<Parametergroup>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        Page<Parametergroup> pageList = parametergroupService.queryPage(page, parametergroup);
        return RspVo.getSuccessResponse(pageList.getTotal(), pageList.getResult());
    }

    /**
     * 批量删除数据字典参数
     * @param checkboxId
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/delParamGroup")
    public @ResponseBody RspVo delParamGroup(String[] checkboxId) {
        parametergroupService.deleteParameterGroup(checkboxId);
        return RspVo.getSuccessResponse();
    }

    /**
     * 新增数据字典参数
     * @param checkboxId
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/addParamGroup")
    public @ResponseBody RspVo addParamGroup(Parametergroup parametergroup) {
        parametergroup.setSgroupNo(codeGeneratorConfigService.generatorCode(PARAMGROUP_CODE));
        parametergroupService.insert(parametergroup);
        return RspVo.getSuccessResponse();
    }

    /**
     * 修改数据字典参数
     * @param checkboxId
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/updateParamGroup")
    public @ResponseBody RspVo updateParamGroup(Parametergroup parametergroup) {
        parametergroupService.updateByPrimaryKey(parametergroup);
        return RspVo.getSuccessResponse();
    }

    /**
     * 查询数据字典参数明细
     * @return
     */
    @RequestMapping("/queryParamGroupDetail")
    public @ResponseBody RspVo<ParameterGroupDetail> queryParamGroupDetail(ParameterGroupDetail parameterGroupDetail,
                                                                                ParamPage paramPage) {
        Page<ParameterGroupDetail> page = new Page<ParameterGroupDetail>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        Page<ParameterGroupDetail> pageList = parameterGroupDetailService.selectByGroupId(page,
            parameterGroupDetail.getSgroupid());
        return RspVo.getSuccessResponse(pageList.getTotal(), pageList.getResult());
    }

    /**
     * 新增数据字典参数明细
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/addParamGroupDetail")
    public @ResponseBody RspVo addParamGroupDetail(ParameterGroupDetail parameterGroupDetail) {
        parameterGroupDetailService.insert(parameterGroupDetail);
        return RspVo.getSuccessResponse();
    }

    /**
     * 修改数据字典参数明细
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/updateParamGroupDetail")
    public @ResponseBody RspVo updateParamGroupDetail(ParameterGroupDetail parameterGroupDetail) {
        parameterGroupDetailService.updateByPrimaryKey(parameterGroupDetail);
        return RspVo.getSuccessResponse();
    }

    /**
     * 批量删除数据字典参数明细
     * @param checkboxId
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/delParamGroupDetail")
    public @ResponseBody RspVo delParamGroupDetail(String[] checkboxId) {
        parameterGroupDetailService.batchDeleteByIds(checkboxId);
        return RspVo.getSuccessResponse();
    }

}
